package com.ruoyi.web.controller.system;

import java.util.List;

import io.swagger.annotations.Api;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.domain.entity.SysUserEmail;
import com.ruoyi.system.service.ISysUserEmailService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户邮箱绑定Controller
 * 
 * @author 许建国
 * @date 2023-10-24
 */
@Api(tags = {"用户邮箱组 Controller"})
@RestController
@RequestMapping("/system/email")
public class SysUserEmailController extends BaseController
{
    @Autowired
    private ISysUserEmailService sysUserEmailService;

    /**
     * 查询用户邮箱绑定列表
     */
    @PreAuthorize("@ss.hasPermi('system:email:list')")
     @GetMapping("/list")
    public TableDataInfo list(SysUserEmail sysUserEmail)
    {
        startPage();
        List<SysUserEmail> list = sysUserEmailService.selectSysUserEmailList(sysUserEmail);
        return getDataTable(list);
    }

    /**
     * 新增用户邮箱绑定
     */
    @PreAuthorize("@ss.hasPermi('system:email:add')")
    @Log(title = "用户邮箱绑定", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysUserEmail sysUserEmail)
    {
        return toAjax(sysUserEmailService.insertSysUserEmail(sysUserEmail));
    }

    /**
     * 修改用户邮箱绑定
     */
    @PreAuthorize("@ss.hasPermi('system:email:edit')")
    @Log(title = "用户邮箱绑定", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysUserEmail sysUserEmail)
    {
        return toAjax(sysUserEmailService.updateSysUserEmail(sysUserEmail));
    }

    /**
     * 删除用户邮箱绑定
     */
    @PreAuthorize("@ss.hasPermi('system:email:remove')")
    @Log(title = "用户邮箱绑定", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysUserEmailService.deleteSysUserEmailByIds(ids));
    }

    /**
     * 修改邮箱状态
     * @param id
     * @return
     */
    @PreAuthorize("@ss.hasPermi('system:email:updateStatus')")
    @PutMapping("/updateStatus")
    public AjaxResult updateStatus(@RequestParam String id){
        return toAjax(sysUserEmailService.updateStatus(id));
    }

}
